/* jpegutil.h 

	JPEG utilities for (de)compression based on libjpeg

Contact: W. Gardner, wgardner@socs.uoguelph.ca
*/

#include <stdio.h>

/*
 * IMAGE DATA FORMATS (from example.c):
 *
 * The standard input image format is a rectangular array of pixels, with
 * each pixel having the same number of "component" values (color channels).
 * Each pixel row is an array of JSAMPLEs (which typically are unsigned chars).
 * If you are working with color data, then the color values for each pixel
 * must be adjacent in the row; for example, R,G,B,R,G,B,R,G,B,... for 24-bit
 * RGB color.
 *
NOTE: The pixels component values are assumed to be "unsigned char"
(instead of JSAMPLE) so that the caller does not need to #include <jpeglib.h>.
 */


/*
readJPEG - decompress JPEG image file into pixel array

1) FILE *file: (input) where to read in JPEG file
2) int *height: (output) height in rows of the decompressed image
3) int *width: (output) width in columns of the decompressed image
4) int *bpp: (output) bytes per pixel (e.g., 3 for 24-bit RGB colour)

unsigned char *: returns pixel array of length height*width*bpp stored
  row-wise, or NULL if a malloc failed; the caller is responsible to free
  this pointer

NOTE: If the file is invalid and decompression fails, the library may
simply print on stderr and call exit(). If that is not acceptable, you
will need to fuss with a custom error handler.
*/
unsigned char *readJPEG(FILE *file, int *height, int *width, int *bpp);


/*
writeJPEG - compress pixel array onto JPEG image file

1) FILE *file: (input) where to write out the JPEG file
2) unsigned char *pic: (input) pixel array
3) int height: (input) height in rows of the pixel array
4) int width: (input) width in columns of the pixel array
5) int bpp: (input) bytes per pixel (e.g., 3 for 24-bit RGB colour)

NOTE: The colour space is assumed to be JCS_RGB.
*/
void writeJPEG(FILE *file, unsigned char *pic, int height, int width, int bpp);
